﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Profari_Heldur_Utan_Um_Prof
{
    public partial class IntroductionTextSession : Form
    {
        public IntroductionTextSession()
        {
            InitializeComponent();
        }

        private static SqlConnection con = new SqlConnection("Data Source=JANA-PC\\SQLEXPRESS;Initial Catalog=dto1;Integrated Security=True " +
  "Initial Catalog=TestDB;Integrated Security=True");
        private static DataTable dt = new DataTable();
        private static SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Introduction", con);
        private static DataSet ds = new DataSet();


        private void btnNext_Click(object sender, EventArgs e)
        {

            //The user is moved to the window where he can put in the web page he wants to evaluate
           /* System.Threading.Thread webPage = new System.Threading.Thread(new System.Threading.ThreadStart(OpenWebPage));

            webPage.Start();
            this.Close();*/
            
     /*       con.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO Introduction(introductionText)" +
                "VALUES(@text)", con);
            cmd.Parameters.AddWithValue("@text", richTextBox1.Text);


            int result = cmd.ExecuteNonQuery();
            if (result > 0)
            {
                MessageBox.Show("Introduction added successfully");
            }
            else
            {
                MessageBox.Show("Error in adding introduction");
            }

            con.Close();*/

            CheckBoxes chbx = new CheckBoxes();
            if (chbx.checkBoxChecked.CheckState == CheckState.Checked)
            {
                System.Threading.Thread form1 = new System.Threading.Thread(new System.Threading.ThreadStart(OpenForm1));
                form1.SetApartmentState(System.Threading.ApartmentState.STA);
                form1.Start();
                this.Close();
            }
            else 
            {
                System.Threading.Thread webPage = new System.Threading.Thread(new System.Threading.ThreadStart(OpenWebPage));
                webPage.SetApartmentState(System.Threading.ApartmentState.STA);
                webPage.Start();
                this.Close();
            }

        }


        private void btnBack_Click(object sender, EventArgs e)
        {
            //User is moved to the window where he can choose if he wants to put some extra in his project, like introduction
            System.Threading.Thread checkBoxes = new System.Threading.Thread(new System.Threading.ThreadStart(OpenCheckBoxes));
            checkBoxes.SetApartmentState(System.Threading.ApartmentState.STA);
            checkBoxes.Start();
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            //If user wants to quit the project he is moved to the first window
            DialogResult cancelProject = MessageBox.Show("Are you sure you want to stop making new project?", "Quit", MessageBoxButtons.YesNo);
            if (cancelProject == DialogResult.Yes)
            {
                System.Threading.Thread testerInterface = new System.Threading.Thread(new System.Threading.ThreadStart(OpenTesterInterface));
                testerInterface.SetApartmentState(System.Threading.ApartmentState.STA);
                testerInterface.Start();
                this.Close();
            }
        }

        //The Open forms functions makes it able to move between forms and close the first form when the second one is opened
        #region OpenForms
        public static void OpenWebPage()
        {
            Application.Run(new WebPage());
        }

        public static void OpenCheckBoxes()
        {
            Application.Run(new CheckBoxes());
        }

        public void OpenTesterInterface()
        {
            Application.Run(new TesterInterface());
        }

        public void OpenForm1()
        {
            Application.Run(new CreateTask());
        }
        #endregion
    }
}
